<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags always come first -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title>短链接解析 | xfunction.cn </title>

  @@include('../include/css-js.html',{ "relatepath":"../.." })

  <style>

  </style>
</head>

<body class="fixed-sn white-skin">
  @@include('../include/progress.html',{"relatepath":"../.." }) @@include('../include/head.html',{"relatepath":"../.."})
  <!--Main Layout-->
  <main>
    <div class="container my-5 z-depth-1">
      <!--Section: Content-->
      <section class="dark-grey-text p-5">
        <!-- Grid row -->
        <div class="row">
          <!-- Grid column -->
          <div class="col-md-4 mb-4 mb-md-0">
            <div class="view" id="qrCode">
              <img src="https://mdbootstrap.com/img/illustrations/undraw_Group_chat_unwm.svg" class="img-fluid">
            </div>
          </div>
          <!-- Grid column -->
          <!-- Grid column -->
          <div class="col-md-8 mb-lg-0 mb-4">
            <h3 class="font-weight-bold my-2">二维码图片还原</h3>
            <input type="file" id="newfile">
            <h3 class="font-weight-bold my-2">或,短链接直接还原</h3>
            <div class="input-group">
              <input type="text" class="form-control" id="shortLinkUrl" placeholder="输入待收缩的网址" >
              <div class="input-group-append">
                <button class="btn btn-md btn-primary rounded-right m-0 px-3 py-2 z-depth-0 waves-effect"
                  type="button"  onclick="restoreShortUrl()">还原</button>
              </div>
            </div>
          </div>
        </div>
        <!-- Grid row -->
      </section>
    </div>
    <div>
      <span id="resultUrl"></span>
    </div>
    <iframe width="100%" height="250px" frameborder=0> </iframe>
  </main>
  <!--Main Layout-->

  @@include('../include/foot.html',{"relatepath":"../.."}) @@include('../include/js-bottom.html',{ "relatepath":"../.."
  })

  <script type="text/javascript">
    // SideNav Initialization
    $(".button-collapse").sideNav();

    var newfile = document.getElementById('newfile');
    var getObjectURL = function (file) {
      var url = null;
      if (window.createObjectURL != undefined) { // basic
        url = window.createObjectURL(file);
      } else if (window.URL != undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file);
      } else if (window.webkitURL != undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
      }
      return url;
    }


    newfile.onchange = function () {
      qrcode.decode(getObjectURL(this.files[0]));
      qrcode.callback = function (imgMsg) {
        $("#shortLinkUrl").val(imgMsg)
        formatResult(imgMsg)
      }
    }

    function restoreShortUrl(){
      var short = $("#shortLinkUrl").val();
      formatResult(short)
    }

    function formatResult(short){

      console.log(short);
      var regFormat = /https:\/\/xfu.biz\/(.+)/;
      var regResult = regFormat.exec(short);
      if(!regResult){
        toastr.error("请检查二维码图片或输入格式,例如https://xfu.biz/zdfXs");
        return;
      }

      var bizLinkId64 = regResult[1];
      var param = {
            bizLinkId64: bizLinkId64
        };
      
      $.ajax({
          type: "post",
          url: baseUrlCon.baseAPI + 'shortLink/redirect',
          contentType: 'application/json',
          data: JSON.stringify(param),
          dataType: "json",
          success: function (data) {
            if (data.success) {
              $("#resultUrl").text("原链接："+data.data);
              $("iframe")[0].src=data.data;
            } else {
              
              toastr.error("请求返回错误");
            }
          },
          error: function () {
            toastr.error("网络请求错误");
          }
        });
    }


  </script>

</body>

</html>